<template>
    <div id="login-registry-container">
		<div class="login-registry-box">		
			<span style="color: white">Tips: 默认密码为 123456, 请登录之后及时前往个人中心更改</span>											
			<Input class="login-registry-input" v-model="name" placeholder="姓名" />
			<Input class="login-registry-input" v-model="sid" placeholder="学号" />
			<Select class="login-registry-input" v-model="dept" placeholder="选择部门">
				<Option v-for="(item, index) in $store.state.info.depts" :value="item.deptName" :key="index">{{ item.deptName }}</Option>
			</Select>
			<Select class="login-registry-input" v-model="group" placeholder="选择小组">
				<Option v-for="(item, index) in groupList" :value="item.groupName" :key="index">{{ item.groupName }}</Option>
			</Select>
			<Select class="login-registry-input" v-model="college" placeholder="选择学院">
				<Option v-for="(item, index) in $store.state.info.colleges" :value="item" :key="index">{{ item }}</Option>
			</Select>
			<Button type="default" ghost @click="registry()">提交</Button>
		</div>
    </div>
</template>

<script>
import stuRequest from '@/axios/student';
import globalJs from '@script/util';

export default {
	data() {
		return {
			name: "",
			sid: "",
			dept: "",
			group: "",
			groupList: [],
			college: ""
		}
	},
	watch: {
		dept(v) {
			this.$store.state.info.depts.forEach(i => {
				if (i.deptName === v) {
					this.groupList = i.groupList;
				}
			});
		}
	},
	methods: {
		async registry() {
			if (this.name.length < 2) {
				this.$Message.warning("请输入正确的姓名");
				return;
			}
			if (this.sid.length != 12 || isNaN(this.sid)) {
				this.$Message.warning("请输入正确的学号");
				return;
			}
			if (this.dept === "") {
				this.$Message.warning("请选择部门");
				return;
			}
			if (this.group === "") {
				this.$Message.warning("请选择小组");
				return;
			}
			if (this.college === "") {
				this.$Message.warning("请选择学院");
				return;
			}
			let res = await stuRequest.registry(this.name, this.sid, this.dept, this.group, this.college);
			if (res === 1) {
				this.$router.replace("/login/entry");
			}
		}
	}
}
</script>

<style lang="scss">
@import "@login/scss/registry-index.scss";
</style>